package gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;

public class PlanetTableFrame extends JFrame
{

	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = -5632979319939832282L;

	private JPanel contentPane;

	private Object[][] cells = { { "Mercury", 2440.0, 0, false, Color.yellow },
	        { "Venus", 6052.0, 0, false, Color.yellow },
	        { "Earth", 6378.0, 1, false, Color.blue },
	        { "Mars", 3397.0, 2, false, Color.red },
	        { "Jupiter", 71492.0, 16, true, Color.orange },
	        { "Saturn", 60268.0, 18, true, Color.orange },
	        { "Uranus", 25559.0, 17, true, Color.blue },
	        { "Neptune", 24766.0, 8, true, Color.blue },
	        { "Pluto", 1137.0, 1, false, Color.black } };

	/** The column names. */
	private String[] columnNames = { "Planet", "Radius", "Moons", "Gaseous",
	        "Color" };

	/**
	 * Create the frame.
	 */
	public PlanetTableFrame()
	{
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setBounds(100, 100, 450, 300);
		this.contentPane = new JPanel();
		this.contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		this.contentPane.setLayout(new BorderLayout(0, 0));
		this.setContentPane(this.contentPane);

		final JTable table = new JTable(this.cells, this.columnNames);
		JScrollPane scrollPanel = new JScrollPane(table);
		this.contentPane.add(scrollPanel, BorderLayout.CENTER);
		JButton btnPrint = new JButton("Print");
		btnPrint.addActionListener(new ActionListener()
		{

			public void actionPerformed(ActionEvent e)
			{
				try
				{
					table.print();
				}
				catch (Exception e2)
				{
					e2.printStackTrace();
				}
			}
		});
		JPanel buttonPanel = new JPanel();
		buttonPanel.add(btnPrint);
		this.add(buttonPanel, BorderLayout.SOUTH);
	}

}
